<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>用户手续费管理</title>
    <style type="text/css">
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
    <script type="text/javascript">
        var grid = null;
        var callback = function () {
            grid.reload();
        };
        $(function () {
            $("#searchBar").ligerForm();
            $("#addPayFreeForm").ligerForm({
                validate: true
            });
            $("#modifyPayFreeForm").ligerForm({
                validate: true
            });
            $("#ligergrid1").ligerGrid({
                url: '<%=path%>/custpay/cmsPayFree/initCmsPayFreeList.do',
                method : 'get',
                columns: [
                    { display: '手机号1', name: 'mp1', minWidth: 100, align: 'center', enabledSort:true},
                    { display: '手机号2', name: 'mp2', minWidth: 100, align: 'center', enabledSort:true},
                    { display: '姓名', name: 'cstNm', minWidth: 100, align: 'center', enabledSort:true},
                    { display: '事业部', name: 'isdept', minWidth: 100, align: 'center', enabledSort:true},
                    { display: '免费次数', name: 'freeNum', minWidth: 100, align: 'center', enabledSort:true},
                    { display: '使用次数', name: 'useNum', minWidth: 100, align: 'center', enabledSort:true},
                    {
                        display: '操作',width: 150,
                        render: function (rowdata, rowindex, value){
                            var h1 = '<a class="sq-button-hasicon" href="javascript:void(0);" onclick="modifycmspayfree('+rowdata.id+')"><i class="sqBtnIco_4"></i>修改</a>'
                            var h2 = '<a class="sq-button-hasicon" href="javascript:void(0);" onclick="removecmspayfree('+rowdata.id+')"><i class="sqBtnIco_7"></i>删除</a>';
                            return h1+h2;
                        }
                    }
                ],
                pageSize:10,
                root:'rows',
                record:'total',
                hideLoadButton : true,
                width: '100%',
                height:'100%',
                heightDiff:-2,
                //checkbox:true,
                rownumbers:true
            });
            grid = liger.get("ligergrid1");

            $("#searchBtn").click(function(event) {
                var form = new liger.get("searchBar");
                var data = form.getData();
                console.log(data);
                for (name in data){
                    grid.setParm(name,data[name]);
                };
                grid.reload();
            });
            $("#clearBtn").click(function(event) {
                clearLigerForm("searchBar");
            });
        });
        //格式化时间
        function renderDate(rowdata, index, value){
            var dateStr = "";
            if(null != value){
                var date = new Date(value);
                dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
            }
            return dateStr;
        }
        //修改
        function modifycmspayfree(id){
            var _dialog = $.ligerDialog.open({
                target: $("#modifyPayFreediv"),
                title: '选择时间',
                width: 500,
                height: 150,
                isResize: true,
                modal: true,
                buttons: [{ text: '保存', onclick: function (i, d) {
                    var form = liger.get("modifyPayFreeForm");
                    if (!form.valid()) {
                        top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO,SQ_type: "warning"});
                        return false; //验证不通过，不执行以下代码
                    }
                    var data = form.getData();
                    data["id"] = id;
                    $("#modifyfreeNum").val("0");
                    _dialog.hide();
                    var wait_dialog;
                    $.ajax({
                        type: 'post',
                        dataType:'json',
                        data:data,
                        url: '<%=path%>/custpay/cmsPayFree/modifyCmsPayFree.do',
                        beforeSend: function(){
                            wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
                        },
                        success:function(msg){
                            wait_dialog.close();
                            if(msg.success == 1){
                                $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
                                grid.reload();
                            }else{
                                $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
                            }
                        }
                    });
                }
                }, { text: '关闭', onclick: function (i, d) {
                    $("#modifyfreeNum").val("0");
                    _dialog.hide();
                }
                }]
            });
        }
        //删除
        function removecmspayfree(id){
            $.ligerDialog.confirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
                if(flag == false)return;
                var wait_dialog;
                $.ajax({
                    type: 'post',
                    dataType:'json',
                    data:{id:JSON.stringify(id)},
                    url: '<%=path%>/custpay/cmsPayFree/removeCmsPayFree.do',
                    beforeSend: function(){
                        wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
                    },
                    success:function(msg){
                        wait_dialog.close();
                        if(msg.success == 1){
                            $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
                            grid.reload();
                        }else{
                            $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
                        }
                    }
                });
            });
        }

        //新增
        function addCmsPayFree(){
                var _dialog = $.ligerDialog.open({
                    target: $("#addPayFreediv"),
                    title: '选择时间',
                    width: 500,
                    height: 150,
                    isResize: true,
                    modal: true,
                    buttons: [{ text: '保存', onclick: function (i, d) {
                        var form = liger.get("addPayFreeForm");
                        if (!form.valid()) {
                            top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO,SQ_type: "warning"});
                            return false; //验证不通过，不执行以下代码
                        }
                        var data = form.getData();
                        var wait_dialog;
                        $.ajax({
                            type: 'post',
                            dataType:'json',
                            data:data,
                            url: '<%=path%>/custpay/cmsPayFree/addCmsPayFree.do',
                            beforeSend: function(){
                                wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
                            },
                            success:function(msg){
                                wait_dialog.close();
                                if(msg.success == 1){
                                    clearLigerForm("addPayFreeForm");
                                    _dialog.hide();
                                    $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
                                    grid.reload();
                                }else{
                                    $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
                                }
                            }
                        });
                    }
                    }, { text: '关闭', onclick: function (i, d) {
                        clearLigerForm("addPayFreeForm");
                        _dialog.hide();
                    }
                    }]
                });
        }
    </script>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox col_33">
                    <div class="label">所属事业部</div>
                    <div class="field">
                        <select name="isdept"  id="isdept"  disabled="disabled">
                            <option value=" " selected="selected">--请选择--</option>
                            <c:forEach items="${orglist}" var="opt">
                                <option value="${opt.key}">${opt.value}</option>
                            </c:forEach>
                        </select>
                    </div>
                    <div style="display: none">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">手机号</div>
                    <div class="field">
                        <input name="phone" id="phone" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">客户名称</div>
                    <div class="field">
                        <input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="clearFix"></div>
                <div class="btnsBox">
                    <span id="searchBtn" class="sq-button sq-button-hasicon"><i class="sqBtnIco_1"></i>查询</span>
                    <span id="clearBtn" class="sq-button sq-button-hasicon"><i class="sqBtnIco_19"></i>清空</span>
                    <span id="addBtn" class="sq-button sq-button-hasicon" onclick="addCmsPayFree()"><i class="sqBtnIco_3"></i>新增</span>
                    <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                </div>
            </div>
        </form>
    </div>
</div>
<div id="ligergrid1" class="sq-grid"></div>
<div id="modifyPayFreediv" style="display:none">
    <form id="modifyPayFreeForm">
        <div class="fieldset1 tabel_col noBorder clearFix">
            <div class="fieldBox col_33">
                <div class="label">免费次数</div>
                <div class="field">
                    <input name="modifyfreeNum" id="modifyfreeNum" type="text" class="ui-textbox" value="0" validate="{required:true}">
                </div>
            </div>
        </div>
    </form>
</div>
<div id="addPayFreediv" style="display:none">
    <form id="addPayFreeForm">
        <div class="fieldset1 tabel_col noBorder clearFix">
            <div class="fieldBox col_33">
                <div class="label">用户手机号</div>
                <div class="field">
                    <input name="addphone" id="addphone" type="text" class="ui-textbox" value="" validate="{required:true}">
                </div>
            </div>
            <div class="clearFix"></div>
            <div class="fieldBox col_33">
                <div class="label">免费次数</div>
                <div class="field">
                    <input name="addfreeNum" id="addfreeNum" type="text" class="ui-textbox" value="" validate="{required:true}">
                </div>
            </div>
            <div class="clearFix"></div>
            <div class="fieldBox col_33">
                <div class="label">事业部</div>
                <div class="field">
                    <select name="addisdept"  id="addisdept" validate="{required:true,select:true}">
                        <option value=" " selected="selected">--请选择--</option>
                        <c:forEach items="${orglist}" var="opt">
                            <option value="${opt.key}">${opt.value}</option>
                        </c:forEach>
                    </select>
                </div>
            </div>
        </div>
    </form>
</div>
</body>
</html>
